package com.hand.endpoint;

import com.hand.dao.CountryRepository;
import com.hand.entity.Country;
import com.hand.entity.CreateCountryRequest;
import com.hand.entity.CreateCountryResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

/*******************Copyright Information************************
 *              AUTHOR: Lorin.Mitchell                           *
 *              DATE: 2017/11/8                                 *
 *              TIME: 14:14                                      * 
 ****************************************************************/
@Endpoint
public class CreateCountryEndpoint {
    private static final String NAMESPACE_URI = "http://www.hand-china.com";

    @Autowired
    private CountryRepository countryRepository;

    //@PayloadRoot注解，表示该方法将处理以namespace和localPart的xml请求信息
    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "createCountryRequest")
    //@ResponsePayload注解，表示将返回值映射到reponse中
    @ResponsePayload
    public CreateCountryResponse createCountryResponse(@RequestPayload CreateCountryRequest request){
        Country country = new Country();
        country.setName(request.getName());
        country.setCapital(request.getCapital());
        country.setCurrency(request.getCurrency());
        country.setPopulation(request.getPopulation());
        countryRepository.save(country);
        return new CreateCountryResponse();
    }
}
